programming4us
           
 
 
SQL Server

Central Management Servers (part 2) - Running Multi-Server Queries

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
10/17/2010 5:54:53 PM

2. Running Multi-Server Queries

One of the appealing new features in SQL Server 2008 is the ability to execute a single query against multiple servers. This can save many hours of mundane work during your career as a DBA. How many times have you written a script that you needed to run on each of your servers? You would not only waste time running the script on each server, but if you needed a centralized result set, you would have to manually combine the results as well. Multi-server queries are not just for selecting data either—think about it from a deployment perspective. For example, you can push a new stored procedure to all the servers in a given group. For that matter, you could even create a new database on every server in the group just by running a single statement. Any script you can write that is compatible with the different versions and editions of all the instances in the group is fair game for execution as a multi-server query.

To run a multi-server query, right-click on a server group and select New Query from the context menu. We will be using the Production group created in the previous section. Clicking New Query from the context menu will open a new query editor window. Your status bar should be a light shade of pink instead of the yellow color that is normally displayed. The status bar will also show the number of servers that the query will execute against by displaying the number of connections made and the number of servers in the group. For example, if you have four servers in a group, you should see Connected (4/4) in the status bar if you are able to make a connection to all four servers. Another interesting thing that happens is that the database drop-down menu is limited to only the databases that are shared by all the servers in the group.

Now we are ready to execute a query. We will execute a simple query to return the name of all the user databases in the server group. For example:

Select name From sysaltfiles Where dbid > 4

Since we have a SQL 2000 instance in the group, we will use the sysaltfiles table instead of the sys.sysaltfiles table that was not available until SQL 2005. Figure 5 shows a result set after executing the query against a group of servers.

Figure 5. Multi-server query result set

If you look at the status bar in Figure 5, you can see a couple of interesting data elements. The status bar shows the name of the group the query is executing against, the user who is executing the query, and the database the query will be executed against. You also may have noticed that the query includes the name of each server as a part of the result set, even though we did not specifically add it to the query.

You can also run multi-server queries using local server groups by registering the servers and running a query against a specific group. The benefit of using a local server group to run a multi-server query is that you can include the central management server in the local server group. Remember that a central management server cannot be a part of the group it is managing, so there is no way to include the server that is managing the groups in the result set. Another benefit to using local server groups to run multi-server queries is that you can register the servers using Windows authentication or SQL Server authentication. The downside to using local server groups is that the groups that are created are local to each DBA. A central management server allows DBAs to share a common registered server group.

Other -----------------
- SQL Server 2008 : The sqlcmd Command-Line Utility
- Installing SQL Server 2008 Using a Configuration File
- SQL Server 2008 : Slipstream Installations
- SQL Server Programmability Objects
- SQL Server 2005 : Data Querying and Reporting (part 2)
- SQL Server 2005 : Data Querying and Reporting (part 1)
- Configuring SQL Server 2008 : Instances vs Default Instance
- sp_configure and SQL Server Management Studio
- Configuring SQL Server 2008 : Database Mail
- Configuring SQL Server 2008 : Full-Text Indexing
- SQL Server 2008 : Working with Indexes
- SQL Server 2008 : Working with Constraints
- SQL Server 2008 : Working with Tables and Views
- SQL Server 2008 : Viewing and Modifying Data (part 3) - Creating Functions and Creating Triggers
- SQL Server 2008 : Viewing and Modifying Data (part 2) - Creating Stored Procedures
- SQL Server 2008 : Viewing and Modifying Data (part 1) - Creating Views
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us